js.underas.container.ModView = new Class({
	"Extends":js.underas.core.Component
	,"_title":""
	,"_icone":"file"
	,"_childrenMods":[]
	,"initialize":function(p_title){
		this._title = p_title;
		this.parent('div','');
		this._childrenMods=[];
		this.getEle().set("data-firstmod","no");
		this.getEle().addClass("tab-content ModView");
		//this.getEle().set("");
		
		$$("#navbarlist li:first.active").removeClass("active");
		$$("#navbarlist").grab(new Element("li",{
				"class":"active"
				,"id":"aba_s_"+this.uid
				,"html":'<a href="#" data-modviewuid="'+this.uid+'" class="btnsabapages"><span class="hidden-xs glyphicon glyphicon-'+this._icone+'"></span> '+this._title+'<span class="x_rmv hidden-xs" data-modviewuid="'+this.uid+'">&otimes;</span></a>'
		}));
		this.getEle().appendHTML(
		'<nav id="pgmod_'+this.uid+'" style="display:none" class="invisible">'
  +'<ul class="pager">'
    +'<li id="previous_'+this.uid+'" class="previous disabled"><a href="#" data-modviewuid="'+this.uid+'"><span class="glyphicon glyphicon-hand-left"></span></a></li>'
    +'<li id="next_'+this.uid+'" class="next"><a href="#" data-modviewuid="'+this.uid+'"><span class="glyphicon glyphicon-hand-right"></span></a></li>'
  +'</ul>'
+'</nav>'
		);
		this.getEle("nav ul.pager li.previous a").addEvent('click',function(event){
			event.preventDefault();
			var uidmodview = this.get("data-modviewuid");
			$("uid_"+uidmodview).getLast(".ModWindow").addClass("hidden-xs");
			$("uid_"+uidmodview).getFirst(".ModWindow").removeClass("hidden-xs");			
			$("next_"+uidmodview).removeClass("disabled");
			$("previous_"+uidmodview).addClass("disabled");
		});
		this.getEle("nav ul.pager li.next a").addEvent('click',function(event){
			event.preventDefault();
			var uidmodview = this.get("data-modviewuid");
			$("uid_"+uidmodview).getFirst(".ModWindow").addClass("hidden-xs");
			$("uid_"+uidmodview).getLast(".ModWindow").removeClass("hidden-xs");			
			$("previous_"+uidmodview).removeClass("disabled");
			$("next_"+uidmodview).addClass("disabled");
		});
		
		//<span class="x_rmv" data-modviewuid="'+this.uid+'">&otimes;</span>
	}
	,"append":function(p_ele){
		var alradyappended = p_ele.getEle().get("data-modview");
		if(!alradyappended){
			this._childrenMods[this._childrenMods.length]=p_ele.getVarModule();			
			if(this.getEle().get("data-firstmod")=="no"){
				this.getEle().set("data-firstmod",p_ele.uid);
			}else{
				p_ele.getEle().addClass("hidden-xs");
				if(this.getEle("nav.invisible")){
					this.getEle("nav.invisible").erase("style").removeClass("invisible").addClass("visible-xs");
				}else{
					console.log("not suport append more than 2 modules!");
				};				
			};
			p_ele.getEle().set("data-modview",this.uid);
			this.getEle().grab(p_ele.getEle());		
		};
	}
	,"destroy":function(){
		var tmChildrens = this._childrenMods.length;
		for(var x = 0 ;x<tmChildrens;x++){
			window[this._childrenMods[x]] = null;
		};

	}
	,"setIcon":function(p_icon){
		this._icone = p_icon;
		//console.log(this._icone);
		$$("#aba_s_"+this.uid+" a span.glyphicon").set('class','hidden-xs glyphicon glyphicon-'+this._icone);
		//.addClass('glyphicon glyphicon-'+this._icone);
	}
	,"showNav":function(on){		
		if(on){
			$$("#aba_s_"+this.uid).setStyle("display","block");
		}else{
			$$("#aba_s_"+this.uid).setStyle("display","none");
		}		
		//alert(idEle.replace("#uid_",""));
		return this;
	}
	,"show":function(on){		
		if(on){
			$$("#conteudo .ModView").setStyle("display","none");
			$$("#navbarlist li.active").removeClass("active");
			$$("#aba_s_"+this.uid).addClass("active").setStyle("display","block");
			this.getEle().addClass("windowCA").setStyle("display","block");
		}else{
			this.getEle().setStyle("display","none").removeClass("windowCA");
		}		
		//alert(idEle.replace("#uid_",""));
		return this;
	}
});




js.underas.container.ModWindow = new Class({
	"Extends":js.underas.core.Component
	,"_urlmodule":""
	,"_revision":""
	,"_subtitle":"&nbsp;&#160;"
	,"_assoc":[]
	,"_dmap":[]
	//,"_varmod":null
	,"_maintoolbar":null
	,"_mainlist":null
	,"_embedItem":null
	,"_embedFather":null
	,"initialize":function(psubtitle){
		this._subtitle = psubtitle;
		this.parent('div',
						'<h3 class="col-sm-12 col-xs-12">'+this._subtitle+'</h3>'+
						'<div class="conteudo_form">'+
					  	'<div class="form-group fbody">'+
						'</div>'+
					  	'<div style="" class="col-sm-12 col-xs-12 form-actions"></div>'+
						'</div>'+
						'<div class="blockrequest normal_load"><div class="BoxTasks" style="display:none"></div></div>'+
						'<h5 class="col-xs-12 col-sm-12 column block_module_details"><span></span></h5>'
						);
		this.getEle().addClass("col-sm-12 col-xs-12 column windowC ModWindow").setStyles({"z-index":(this.uid+1)});
		
		
		this.getEle().getElement(".blockrequest").set("id","tge_"+this.uid).addEvents({ 
				'click': function(evt){ 
					js.underas.net.RequestManager.showAllTasks(evt.target.get("id"));
				}, 
				'dblclick': function(evt){ 
					js.underas.net.RequestManager.removeAllTasks(evt.target.get("id"));
				} 
			}); 
		this._maintoolbar = null;
		this._mainlist = null;
		this._embedItem = null;
		this._embedFather = null;
	}
	,"_onStart":function(){
		//Object.each(this);
		//console.log('NOVO LOOP');
		var nextMapInd = 0;//this._dmap.length;
		var _this = this;
		Object.each(this, function(value, key){
			if(!key.match("_embedFather|_embedItem|_assoc|_dmap|$caller|caller|_subtitle|uid|_html|_revision|_maintoolbar|_mainlist|_urlmodule|_varmod")){
				//console.log('k:' + key + '');								
				if(_this[key]["getColumn"]){
					if(_this[key].getColumn()){																
						var obj_chave = {"column":_this[key].getColumn(),"field":key};
						_this._dmap[nextMapInd] = obj_chave;
						if(_this[key].isPrimaryKey()){
							_this.setIdField(key);
						}
						nextMapInd++;
					}
				}else if(_this[key]["_istoolbar"]){
					_this._maintoolbar = key;
				}else if(_this[key]["_islistview"]){
					if(!_this.getMainList()){
						_this.setMainList(key);
					};
				};			
			};							
		});
	}
	,"onStart":function(){}
	,"getFormItem":function(){
		var modTmp = this;
		var tmpColumns = modTmp.getColumns();
		var objForm = {};
		tmpColumns.each(function(cfield,index){
			//var tmpField = this.getModule()[cfield["field"]];			
			var fieldTmp = cfield["field"];
			if(!modTmp[fieldTmp]){
				console.log("change item #erro: field "+fieldTmp+" not exist!");
			}else{
				objForm[cfield["column"]] = modTmp[fieldTmp].getValue();				
			}				
		});	
		return objForm;
	}
	,"clearFormItem":function(){
		var modTmp = this;
		var tmpColumns = modTmp.getColumns();
		tmpColumns.each(function(cfield,index){
			//var tmpField = this.getModule()[cfield["field"]];			
			var fieldTmp = cfield["field"];
			if(!modTmp[fieldTmp]){
				console.log("change item #erro: field "+fieldTmp+" not exist!");
			}else{
				if(!(modTmp[fieldTmp].getEle().hasClass("Select")||modTmp[fieldTmp].isFixed())){
					modTmp[fieldTmp].setValue("");
				}
			}				
		});	
	}
	,"setRevision":function(p_txt_revision){
		this._revision = p_txt_revision.replace(/[^\d]+/g,'');
	}
	,"getRevision":function(){
		return this._revision;
	}
	,"getDsModule":function(){		
		var urltmp = this.getUrlModule().replace(".js","").toUpperCase();
		var urltmpa = urltmp.split("/");
		var tmurls = urltmpa.length;
		return urltmpa[tmurls-3]+" | "+urltmpa[tmurls-1];
	}
	,"setUrlModule":function(p_url_m){
		this._urlmodule = p_url_m;
	}
	,"getUrlModule":function(){
		return this._urlmodule;
	}
	,"setVarModule":function(p_varmod){
		if(p_varmod){
			this.getEle().set("data-varmod",p_varmod);
			this["_varmod"]=p_varmod;
		}
	}
	,"getVarModule":function(){
		return this._varmod;
	}	
	,"getModView":function(){
		var uidModView =  "modview_"+this.getEle().get("data-modview");
		return window[uidModView];
	}	
	,"append":function(childtoappend){
		if(childtoappend.getEle().hasClass("btn")){
			this.getEle("div.form-actions").grab(childtoappend.getEle());
		}else if(childtoappend.getEle().hasClass("ListView")||childtoappend.getEle().hasClass("ListViewAdv")){
			this.getEle("div.conteudo_form").grab(childtoappend.getEle());
			childtoappend.setVarModule(this.getVarModule());
		}else if(childtoappend.getEle().hasClass("ToolBar")){
			childtoappend.setVarModule(this.getVarModule());
			this.getEle("div.conteudo_form").grab(childtoappend.getEle(),'top');
		}else if(childtoappend.getEle().hasClass("preview-pane")){
			this.getEle("div.fbody").grab(childtoappend.getEle());
		}else{
			this.getEle("div.fbody").grab(childtoappend.getEle());
			if(childtoappend.getEle().hasClass("Controller")){
				childtoappend.setVarModule(this.getVarModule());
			}
		}
	}
	,"addAssociation":function(p_assoc){		
		if(this._dmap.length==0){
			this._onStart();
		};				
		//por padrao pega o field principal se nao for especificado nenhum field
		var configstmp = Object.merge({"mod":"","url":"","act":"","p":[],"puid":this.getVarModule(),"field":this.getIdField()},p_assoc);
		this._assoc[this._assoc.length]=configstmp;	
	}
	,"getAssociations":function(){	
		return this._assoc;	
	}	
	,"setDsModule":function(){
		this.getEle("h5.block_module_details").set("html","<span>"+this.getDsModule()+" :"+this.getRevision()+"</span>");
	}
	,"getColumns":function(){
		return this._dmap;
	}
	,"setIdField":function(p_field){
		this.getEle().set("data-idfieldcod",p_field);
	}
	,"getIdField":function(){		
		if(!this.getEle().get("data-idfieldcod")){
			var pkC =  this.getColumns()[0];
			if(pkC){
				this.setIdField(pkC.field);
			}else{
				console.log("id nao definido");
			};			
		};
		return this.getEle().get("data-idfieldcod");
	}
	,"getMainList":function(){
		//if(!this._mainlist){
			//this._mainlist = "mainList";
		//}
		return this[this._mainlist];
	}
	,"setMainList":function(p_main_list){
		this._mainlist=p_main_list;
	}
	,"show":function(on){
		if(on){
			this.getEle().setStyle("display","block");
		}else{
			this.getEle().setStyle("display","none");
		}		
	}
	,"beforeSave":function(p_obj){
		return p_obj;
	}
	,"beforeInsert":function(p_req_obj){
		return p_req_obj;
	}
	,"beforeQuery":function(p_req){
		return p_req;
	}
	,"onChangeItem":function(p_obj){
		return p_obj;
	}
	,"beforeDelete":function(p_req_delete,p_old_obj){
		return p_req_delete;	
	}
	,"beforeUpdate":function(p_new_obj,p_old_obj){
		return p_new_obj;	
	}
});




js.underas.container.AlertWindow = new Class({
	"Extends":js.underas.core.Component
	,"_title":""
	,"_icone":"file"
	,"initialize":function(p_title,p_msg){
		this._title = p_title;
		this.parent('div','<div class="modal-dialog">'
                  +'<div class="modal-content">'
                    +'<div class="modal-header">'
                      +'<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>'
                      +'<h4 class="modal-title">'+p_title+'</h4>'
                    +'</div>'
                    +'<div class="modal-body">'
                      +'<p>'+p_msg+'</p>'
                    +'</div>'
                    +'<div class="modal-footer"></div>'
                  +'</div>'
                +'</div>');
		this.getEle().addClass("AlertWindow modal");
		this.getEle("button.close").addEvent('click',function(event){
			event.preventDefault();
			this.show(false);
		}.bind(this));		
		//<span class="x_rmv" data-modviewuid="'+this.uid+'">⊗</span>
	}
	,"addButton":function(p_ele,p_soe){
		var pso = p_soe||"top";
		this.getEle(".modal-footer").grab(p_ele.getEle(),pso);
	}
	,"setTitle":function(p_title){
		this.getEle(".modal-title").set("text",p_title);
	}
	,"setMsg":function(p_msg){
		this.getEle(".modal-body p").set("text",p_msg);
	}
});
